package com.jsmile.cloud.tradecenter.express.feign;

import java.util.List;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.jsmile.cloud.tradecenter.api.req.express.ReqExpressQuery;
import com.jsmile.cloud.tradecenter.api.res.express.ResExpressCompany;
import com.jsmile.cloud.tradecenter.express.ExpressCompanyApplicationService;
import com.jsmile.cloud.tradecenter.express.kit.Kuaidi100Kit;
import com.jsmile.mail.security.controller.AuthcController;
import com.jsmile.mail.security.handler.JsmileContext;
import com.jsmile.mall.api.JSmileResult;
import com.jsmile.mall.api.annotation.CurrentContext;
import com.jsmile.mall.api.constants.JSmileConstant;
import com.jsmile.mall.api.enums.LogTypeEnum;
import com.jsmile.mall.log.annotation.JsmileLog;

import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@AllArgsConstructor
@Api(tags = "订单管理")
public class ExpressServiceApiImpl extends AuthcController {

    private final ExpressCompanyApplicationService expressCompanyApplicationService;

    @RequestMapping(value = "/feign/express/query", method = RequestMethod.POST)
    @JsmileLog(title = "订单中心->物流查询", type = LogTypeEnum.QUERY, systemId = JSmileConstant.SystemId.TRADE_CENTER)
    public JSmileResult<JSONObject> query(@RequestBody @Valid ReqExpressQuery reqExpressQuery, @CurrentContext JsmileContext jsmileContext) {
        return JSmileResult.success(Kuaidi100Kit.kuadi100Query(reqExpressQuery.getPhone(), reqExpressQuery.getCompanyCode(), reqExpressQuery.getExpressNo()));
    }

    @RequestMapping(value = "/feign/express/findAll", method = RequestMethod.POST)
    @JsmileLog(title = "订单中心->物流公司查询", type = LogTypeEnum.QUERY, systemId = JSmileConstant.SystemId.TRADE_CENTER)
    public JSmileResult<List<ResExpressCompany>> findAll(@RequestBody @Valid ReqExpressQuery reqExpressQuery, @CurrentContext JsmileContext jsmileContext) {
        reqExpressQuery.setCurTenantId(jsmileContext.getTenantId());
        return JSmileResult.success(expressCompanyApplicationService.findAll(reqExpressQuery));
    }
}
